package ren.steve.system.config;


import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: LiuGuoJia
 * @Description:
 * @Date: Created in 2024/1/18 16:57
 */

@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfig {

  @Bean
  public Docket adminAPIConfig () {
    List<Parameter> pars = new ArrayList<>();
    ParameterBuilder tokenPar = new ParameterBuilder();
    tokenPar.name("token")
      .description("用户 Token")
      .defaultValue("")
      .modelRef(new ModelRef("string"))
      .parameterType("header")
      .required(false)
      .build();
    pars.add(tokenPar.build());

    Docket docket = new Docket(DocumentationType.SWAGGER_2)
      .groupName("API System")
      .apiInfo(adminAPIInfo())
      .select()
      .apis(RequestHandlerSelectors.basePackage("ren.steve"))
      .paths(PathSelectors.regex("/api/.*"))
      .build()
      .globalOperationParameters(pars);

    return docket;
  }

  public ApiInfo adminAPIInfo () {
    return new ApiInfoBuilder()
      .title("API : System Document")
      .description("本文档描述了后台管理系统微服务接口定义")
      .version("1.0.0")
      .contact(new Contact("Liu GuoJia", "http://steve.ren", "guojia.liu@lingyue-digital.com"))
      .build();
  }

}
